#include <iostream>
using namespace std;

const int N = 100010;

class mon_queue
{
private:
    int q[N];
    int hh;
    int tt;
    int mon;

public:
    mon_queue(int m = 1);
    void push(int x);
    int pop();
    int query();
    int len();
};

mon_queue::mon_queue(int m)
{
    mon = m;
    hh = 0;
    tt = -1;
}

void mon_queue::push(int x)
{
    while (len() && (mon * q[tt]) >= (mon * x))
        tt--;
    q[++tt] = x;
    return;
}

int mon_queue::pop()
{
    return q[hh++];
}

int mon_queue::query()
{
    return q[hh];
}

int mon_queue::len()
{
    return tt - hh + 1;
}

int main()
{
    int n, x;
    mon_queue que(-1);
    scanf("%d", &n);
    while (n--)
    {
        scanf("%d", &x);
        que.push(x);
    }
    while (que.len())
        printf("%d ", que.pop());
    return 0;
}